package day24;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 *
 * PictureUploadClient.java
 * @author wangbiao<br/>
 *         email:785497344@qq.com
 * @description 上传图片的客户端
 * @since 1.0.0
 * @date 2013-7-12下午11:42:03
 *
 */
public class PictureUploadClient {

	public static void main(String[] args) {
		Socket s = null;
		FileInputStream fis = null;
		try {
			s = new Socket("192.168.1.102", 10000);
			OutputStream out = s.getOutputStream();
			
			fis = new FileInputStream("D:\\400.jpg");
			int len = 0;
			byte[] buf = new byte[1024];
			while ((len=fis.read(buf)) != -1) {
				out.write(buf, 0, len);
			}
			//写入结束标记
			s.shutdownOutput();
			
			InputStream in = s.getInputStream();
			byte[] buffer = new byte[1024];
			int length = in.read(buffer);
			System.out.println("服务端反馈信息 "+new String(buffer, 0, length));
			
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (null != fis) {
				try {
					fis.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (null != s) {
				try {
					s.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
